/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ruipengkj.bean.TShopMsg;
import com.ruipengkj.commons.base.query.BaseQuery;
import com.ruipengkj.commons.base.query.PageModel;
import com.ruipengkj.dao.TShopMsgDao;
import com.ruipengkj.service.TShopMsgService;
/**
 * 说明：
 * 商店充值规则Service层接口实现
 * @Author：李智深
 * @Date：2012-03-16
 */
@Service
public class TShopMsgServiceImpl implements TShopMsgService{
	@Resource
	private TShopMsgDao TShopMsgDao;//DAO层
	//查询所有
	@Override
	public List<TShopMsg> findService(TShopMsg entity) throws Exception {
		String hql = "select o from TShopMsg o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
//			whereHQL.append("StartTime<=now()").append(BaseQuery.AND);
//			//param.add(entity.getEndTime());
//			whereHQL.append("EndTime>=now()").append(BaseQuery.AND);
			
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TShopMsgDao.findDao(hql, whereHQL.toString(), param, orderby);
	}

	//根据ID翻页查询
	@Override
	public PageModel<TShopMsg> getScrollService(int firstResult,
			int maxResult, TShopMsg entity) throws Exception {
		String hql = "select o from TShopMsg o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getTitle()!=null&&!entity.getTitle().equals("")){
				whereHQL.append("Title").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getTitle()+"%");
			}
				whereHQL.append("TYPE=2").append(BaseQuery.AND);			
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TShopMsgDao.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}

	//修改
	@Override
	public void modifyService(TShopMsg entity) throws Exception {
		TShopMsgDao.modifyDao(entity);
		
	}
	//添加
	@Override
	public void saveService(TShopMsg entity) throws Exception {
		TShopMsgDao.saveDao(entity);
	}
	//根据ID删除
	@Override
	public void deleteService(String id) throws Exception {
		TShopMsgDao.deleteDao(id);
		
	}
	//根据ID查询
	@Override
	public TShopMsg getByIdService(String id) throws Exception {
		return TShopMsgDao.getByIdDao(id);
	}
	//添加或修改
	@Override
	public void saveOrUpdateService(TShopMsg entity) throws Exception {
		TShopMsgDao.saveOrUpdateDao(entity);
	}
	//添加返回ID
	@Override
	public Serializable saveRetService(TShopMsg entity) throws Exception {
		return TShopMsgDao.saveRetDao(entity);
	}
	public TShopMsgDao getTShopChargeDao() {
		return TShopMsgDao;
	}

	public void setTShopMsgDao(TShopMsgDao TShopMsgDao) {
		this.TShopMsgDao = TShopMsgDao;
	}
	@Override
	public PageModel<TShopMsg> getTShopChargeService(int firstResult,
			int maxResult, TShopMsg entity) throws Exception {
			String hql = "select o from TShopMsg o";
			StringBuffer whereHQL = new StringBuffer();
			List<Object> param = new ArrayList<Object>();
			if (entity != null) {
				if(entity.getTitle()!=null&&!entity.getTitle().equals("")){
					whereHQL.append("Title").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
					param.add("%"+entity.getTitle()+"%");
				}
					whereHQL.append("TYPE=2").append(BaseQuery.AND);				
				if(whereHQL.length()>4)
					whereHQL.delete(whereHQL.length()-5, whereHQL.length());
			}
			LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
			orderby.put("CreateTime", "desc");
			return TShopMsgDao.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}
}